-
Notifications
You must be signed in to change notification settings - Fork 150
cc_toolchain's tool_map should be cfg-exec-configured #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ca23f76 to
a91a95d
Compare
63ff83e to
cc175a4
Compare
0ac92cf to
ad72f0e
Compare
armandomontanez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this together! I'll try to take a closer look early next week. If I don't get back to you in a timely manner, please ping me with a comment here.
21a6ab9 to
79f0585
Compare
79f0585 to
2574ba4
Compare
@armandomontanez PTAL :) |
armandomontanez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more small things, but overall looks great!
The macOS build is failing because macOS is currently doing a cross-compile to Linux and the tools are now exec-configured. This means llvm-libtool-darwin is getting selected as the archiver, but we end up using ar-style flags. Easy fix is to just merge the two tool maps to always use llvm-ar instead of llvm-libtool-darwin:
| # This `select` happens under the target configuration. For macOS, | |
| # llvm-libtool-darwin should be used when creating static libraries even if the | |
| # exec platform is linux. | |
| alias( | |
| name = "all_tools", | |
| actual = select({ | |
| "@platforms//os:macos": ":macos_tools", | |
| "//conditions:default": ":default_tools", | |
| }), | |
| tags = ["manual"], | |
| visibility = ["//visibility:public"], | |
| ) | |
| COMMON_TOOLS = { | |
| "@rules_cc//cc/toolchains/actions:assembly_actions": ":clang", | |
| "@rules_cc//cc/toolchains/actions:c_compile": ":clang", | |
| "@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":clang++", | |
| "@rules_cc//cc/toolchains/actions:link_actions": ":lld", | |
| "@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":llvm-objcopy", | |
| "@rules_cc//cc/toolchains/actions:strip": ":llvm-strip", | |
| } | |
| cc_tool_map( | |
| name = "default_tools", | |
| tags = ["manual"], | |
| tools = COMMON_TOOLS | { | |
| "@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-ar", | |
| }, | |
| visibility = ["//visibility:private"], | |
| ) | |
| cc_tool_map( | |
| name = "macos_tools", | |
| tags = ["manual"], | |
| tools = COMMON_TOOLS | { | |
| "@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-libtool-darwin", | |
| }, | |
| visibility = ["//visibility:private"], | |
| ) |
A number of projects prefer ar style archivers for cross-language interop reasons anyways.
| known_features = known_features, | ||
| enabled_features = enabled_features, | ||
| compiler = compiler, | ||
| cpu = select({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move these to a shared constant rather than copying. These CPU values are arcane, so minimizing duplication is important.
| @@ -0,0 +1,46 @@ | |||
| # Copyright 2018 The Bazel Authors. All rights reserved. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright year needs to be current year for new files.
| } | CC_TOOLCHAIN_CONFIG_PUBLIC_ATTRS | { | ||
| # Override tool_map to make it optional. | ||
| "tool_map": attr.label( | ||
| cfg = "exec", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this is handled properly, we need to remove the exec transition in the cc_tool_map:
rules_cc/cc/toolchains/tool_map.bzl
Line 59 in e6d30a5
| cfg = "exec", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm might want to pick with a condition matching whether or not this is enabled (_bazel_version_ge("9.0.0-pre.20250911"))
To prevent duplication, it might be best to abstract that check with something like bazel_supports_starlarkified_cc_toolchians()
However, it's not enough for
tool_mapto be oncc_toolchain_config- it must be on the toolchain itself to properly share the same exec platform as the action requesting the toolchain. Therefore we rearrange the implementation of thecc_toolchainmacro to pass it to the rule, and teach the rule to accept it from either the attribute or thecc_toolchain_config.Eventually,cc_toolchain_configcan be retired, though it will be a long journey.